//
//  Seller_StockTableViewCell.m
//  HappyRent
//
//  Created by CoderYee on 2017/4/10.
//  Copyright © 2017年 内圈科技. All rights reserved.
//

#import "Seller_StockTableViewCell.h"

@interface Seller_StockTableViewCell ()

{
    UIView   *_topView;
    UIView   *_bottomView;
    NSMutableArray  *_buttons;
    
}

@end

@implementation Seller_StockTableViewCell

-(void)addOwnView{
    
    [self.contentView setBackgroundColor:kBackgroundColor];
    _buttons=[[NSMutableArray alloc] init];
    [self  addtopView];
    [self  addBottomView];
    
}
-(void)addtopView{
    
    _topView=[[UIView alloc] init];
    [_topView setBackgroundColor:kWhiteColor];
    [self.contentView addSubview:_topView];
    [_topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.contentView);
        make.height.mas_equalTo(80);
    }];
    

    _stockImageView=[[UIImageView alloc] init];
    _stockImageView.contentMode=UIViewContentModeScaleAspectFill;
    _stockImageView.clipsToBounds=YES;
    _stockImageView.image = placeImage;
    [_topView addSubview:_stockImageView];
    [_stockImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_topView).with.offset(10);
        make.centerY.equalTo(_topView);
        make.height.width.mas_equalTo(60);
    }];
    
    _titleLable=[[UILabel alloc] init];
    _titleLable.text=@"套系套系套系套系套系套系套系套系套系套系套系套系套系套系套系套系套系套系";
    _titleLable.textColor=kBlackColor;
    _titleLable.font=systemfont(14);
    _titleLable.numberOfLines=0;
    [_topView addSubview:_titleLable];
    [_titleLable mas_makeConstraints:^(MASConstraintMaker *make)
    {
        make.left.equalTo(_stockImageView.mas_right).offset(10);
        make.right.equalTo(_topView).with.offset(-5);
        make.centerY.equalTo(_topView);
    }];
    
    
}
-(void)addBottomView{
   
    _bottomView=[[UIView alloc] init];
    [_bottomView setBackgroundColor:kWhiteColor];
    [self.contentView addSubview:_bottomView];
    
    [_bottomView setFrame:CGRectMake(0, 88, kMainScreenWidth, 38)];
    //设置buttons
    _editButton=[UIButton buttonWithType:UIButtonTypeCustom];
    _removeButton=[UIButton buttonWithType:UIButtonTypeCustom];
    _deleteButton=[UIButton buttonWithType:UIButtonTypeCustom];
    _shareButton=[UIButton buttonWithType:UIButtonTypeCustom];
    
    [_bottomView addSubview:_editButton];
    [_bottomView addSubview:_removeButton];
    [_bottomView addSubview:_deleteButton];
    [_bottomView addSubview:_shareButton];

    
}
-(void)layoutSubviews{
    
    [super layoutSubviews];
}

-(void)configTableView:(UITableView *)tableView withModel:(BaseModel*)model withVcType:(Seller_StockTableViewCellType)Type{
    
    [_buttons removeAllObjects];
    if (Type==StockTableViewSendCellType) {
        
        [_buttons addObjectsFromArray:@[_editButton,_removeButton,_deleteButton,_shareButton]];
        
        NSArray *titleArray=@[@"编辑",@"下架",@"删除",@"分享"];
        CGFloat width = 70;
        CGFloat margin =(kMainScreenWidth-4*70)/5.0;
        for (NSUInteger i=0; i<_buttons.count; i++) {
            
            UIButton *btn=_buttons[i];
            [btn setFrame:CGRectMake(width*i+margin*(i+1), 3, width, 30)];
            [btn setImage:kImage(@"tabbar_setting") forState:UIControlStateNormal];
            btn.titleEdgeInsets=UIEdgeInsetsMake(0, 5, 0, 0);
            btn.titleLabel.font=systemfont(14);
            [btn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
            [btn setTitle:titleArray[i] forState:UIControlStateNormal];
            [btn setTitleColor:kBlackColor forState:UIControlStateNormal];
        }
        
    }else
    {
      
        [_buttons addObjectsFromArray:@[_editButton,_removeButton,_deleteButton]];
        NSArray *titleArray=@[@"编辑",@"上架",@"删除",];
        CGFloat width = 70;
        CGFloat margin =(kMainScreenWidth-3*70)/4.0;
        for (NSUInteger i=0; i<_buttons.count; i++) {
            
            UIButton *btn=_buttons[i];
            [btn setFrame:CGRectMake(width*i+margin*(i+1), 3, width, 30)];
            [btn setImage:kImage(@"tabbar_setting") forState:UIControlStateNormal];
            btn.titleEdgeInsets=UIEdgeInsetsMake(0, 5, 0, 0);
            btn.titleLabel.font=systemfont(14);
            [btn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
            [btn setTitle:titleArray[i] forState:UIControlStateNormal];
            [btn setTitleColor:kBlackColor forState:UIControlStateNormal];
        }
        
    }
    
    
    
}
#pragma mark 点击按钮事件
-(void)clickButton:(UIButton *)sender{
    
    if (self.delegate&&[self.delegate respondsToSelector:@selector(clickTableView:withtouchView:EventType:)]) {
        
        [self.delegate clickTableView:self withtouchView:sender EventType:TableClickEventValue1];
    }
    
    
}
@end
